﻿// -----------------------------------------------------------------------
// <copyright file="EntityEN.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Reflection;
namespace VDC.VONE.ENTITIES
{
    /// <summary>
    /// Class EntityEN
    /// </summary>
    public class EntityEN
    {
        /// <summary>
        /// Create a copy with type of string has trim
        /// </summary>
        /// <returns>return EntityEN</returns>
        public EntityEN Copy()
        {
            var entityEN = Activator.CreateInstance(this.GetType());
            
            PropertyInfo[] properties = entityEN.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo propertyInfo in properties)
            {
                if(propertyInfo.CanRead && propertyInfo.CanWrite)
                {
                    PropertyInfo property = this.GetType().GetProperty(propertyInfo.Name);
                    var value = property.GetValue(this, null);
                    propertyInfo.SetValue(entityEN, value, null);
                    if(propertyInfo.PropertyType == typeof(string))
                    {
                        propertyInfo.SetValue(entityEN, string.Format("{0}", value).Trim(), null);
                    }
                }
            }

            return (EntityEN)entityEN;
        }
    }
}
